package com.leo.simple.job;

import com.leo.bean.Counter;
import org.quartz.*;

import java.time.LocalDateTime;

/**
 * @ClassName ConcurrentJob
 * @Description 并发执行测试
 * @Author wangss
 * @date 2021.07.15 10:02
 * @Version 1.0
 */
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class ConcurrentJob implements Job {

    private Counter counter;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobKey key = jobExecutionContext.getJobDetail().getKey();
        JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();

        System.out.println("job = [" + key + "], idx = [" + counter.incr() + "], date = [" + LocalDateTime.now() + "]");
    }

    public void setCounter(Counter counter) {
        this.counter = counter;
    }
}
